package com.powerband.apiheartrate.ble.fbkBleController

import kotlin.jvm.Volatile
import com.powerband.apiheartrate.ble.bleCommand.PYBleCommand
import java.util.ArrayList
import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock

class FBKBleCmdManager {
    var bleCmdArray: MutableList<PYBleCommand> = ArrayList()
    private val m_cmdLock: Lock = ReentrantLock()
    fun addBleCommand(bleCommand: PYBleCommand):Boolean {
        m_cmdLock.lock()
        bleCmdArray.add(bleCommand)
        m_cmdLock.unlock()
        return true
    }

    val bleCommand: PYBleCommand?
        get() {
            var sendCommand: PYBleCommand? = null
            m_cmdLock.lock()
            if (bleCmdArray.size > 0) {
                sendCommand = bleCmdArray[0]
                bleCmdArray.removeAt(0)
            }
            m_cmdLock.unlock()
            return sendCommand
        }

    fun clearBleCommand() {
        m_cmdLock.lock()
        bleCmdArray.clear()
        m_cmdLock.unlock()
    }
}